<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// 		http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".

ini_set('include_path', '.');

//error_reporting(E_ALL);


// experimental caching
// 0 = off
// 1 = on
define('caching', 1);

define('summarize_mysql', 1);




// DO NOT EDIT THIS FILE. USE THE ADMIN PANEL (logged in as "god") TO MAKE CHANGES


// IF YOU MUST MAKE CHANGES MANUALLY, EDIT SETTINGS.PHP



/*
 * strip potentially harmful characters from uncontrolled input vars, so
 * that naive code can use them without introducing security problems.
 * security-aware code can get the originals from $GLOBALS['_unsafe'].
 *
 * xxx this is weak protection.  there are some attacks that might be able
 * to sneak past this.
 */
function sanitize_globals() {
    static $done = 0;
    if ($done++) return;
    sanitize_globals_1($_REQUEST, 'request');
    sanitize_globals_1($_GET, 'get');
    sanitize_globals_1($_POST, 'post');
    sanitize_globals_1($_COOKIE, 'cookie');
    sanitize_globals_1($_SERVER, 'server');
    // don't bother sanitizing $HTTP_SERVER_VARS
    $GLOBALS['HTTP_SERVER_VARS'] = 'use $_SERVER instead';
}

function sanitize_globals_1($array, $savename) {
    $GLOBALS['_unsafe'][$savename] = $array;
    foreach ($array as $key => $value) {
        if (is_string($value)) {
            $array[$key] = preg_replace('{["\'`<>&\\\\]}', '', $value);
        }
    }
}

// not enabled yet
// sanitize_globals();



define("mnmpath", dirname(__FILE__).'/');
define("mnminclude", dirname(__FILE__).'/libs/');
define("mnmmodules", dirname(__FILE__).'/modules/');

include_once mnminclude . 'pre_install_check.php';

include_once 'settings.php';
if ($my_base_url == '' || strpos($_SERVER['SCRIPT_NAME'], "admin_config.php") > 0){
	define('my_base_url', "http://" . $_SERVER["HTTP_HOST"]);
	if(isset($_REQUEST['action'])){$action = $_REQUEST['action'];}else{$action="";}
	
	$pos = strrpos($_SERVER["SCRIPT_NAME"], "/");
	$path = substr($_SERVER["SCRIPT_NAME"], 0, $pos);
	if ($path == "/"){$path = "";}

	define('my_pligg_base', $path);
	$my_pligg_base = $path;
} else {
	define('my_base_url', $my_base_url);
	define('my_pligg_base', $my_pligg_base);
}

define('urlmethod', $URLMethod);

$language = 'english';
define('pligg_language', $language);

if(Enable_Extra_Fields){include mnminclude.'extra_fields.php';}

// Don't touch behind this
$local_configuration = $_SERVER['SERVER_NAME'].'-local.php';
@include($local_configuration);

include_once mnminclude.'define_tables.php';

//
// start summarization and caching of mysql data
//

	// added to replace 55 redundant queries with 1
	// used with the following functions in /lib/link.php
	//	function category_name() {
	//	function category_safe_name() {
	// cache the data if caching is enabled

		if(caching == 1){
			$db->cache_dir = mnmpath.'cache';
			$db->use_disk_cache = true;
			$db->cache_queries = true;
		}
		
		// if this query changes, be sure to change the 'clear the cache' code in admin_categories.php
		$the_cats = $db->get_results("select category_id, category__auto_id, lft, rgt, category_name, category_safe_name, category_lang, category_desc, category_keywords from ".table_categories." ORDER BY lft ASC;");
		$cached_categories = $the_cats;

		$db->cache_queries = false;
	
	// a simple cache type system for the users table
	// used in the read() function of /libs/user.php
	$cached_users = array();
	
	// a simple cache type system for the totals table
	// functions related to this are in /libs/html1.php	
	$cached_totals = array();

	$cached_votes = array();

	$cached_links = array();

	$cached_saved_links = array();
//
// end summarization and caching of mysql data
//

ob_start();
include_once mnminclude.'db.php';
include mnminclude.'utils.php';
if(!isset($include_login) || $include_login !== false){
	// if $include_login is set to false (like in jspath.php and xmlhttp.php), then we don't
	// include login, because login will run a query right away to check user credentials
	// and these two files don't require that.
	include_once mnminclude.'login.php';
}
include_once(mnmmodules . 'modules_init.php');
include mnminclude.'utf8/utf8.php';
include_once(mnminclude.'dbtree.php');
?>
